$(function () {
    let form = layui.form

    form.verify({
        pwd: [/^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格'],
        samePwd: function (value) {
            if (value === $('[name=oldPwd]').val()) {
                return '新旧密码不能相同！'
            }
        },
        rePwd: function (value) {
            if (value !== $('[name=newPwd]').val()) {
                return '两次密码不一致！'
            }
        }
    })
})

$('.layui-form').on('submit', function (e) {
    e.preventDefault()
    const data = $(this).serialize()
    $.ajax({
        method: 'POST',
        url: '/my/userinfo',
        data,
        success: res => {
            const {
                status
            } = res
            if (status !== 0) {
                return layui.layer.msg('修改密码失败')
            }
            layui.layer.msg('修改密码成功')
            $('.layui-form')[0].reset()
        }

    })
})